package servlet;

import dao.ArticleDao;
import dao.daoimpl.ArticleDaoImpl;
import bean.Article;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name="RecordServlet",urlPatterns = "/RecordServlet")
public class RecordServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");/*防止乱码*/
        Article article=(Article) request.getSession().getAttribute("blogArticle");
        ArticleDao articleDao=new ArticleDaoImpl();
        try {
            if(articleDao.updateArticle(article)){
                System.out.println("文章保存成功");
            }else{
                System.out.println("文章保存失败");
            }
        } catch (SQLException sqlException) {
            sqlException.printStackTrace();
        }
    }
}
